<?php


namespace common\helpers;


use common\services\ConfigService;
use Yii;
use yii\db\Exception;

/**
 * 守护进程使用方法
 * cd /etc/systemd/system
 * 创建一个xxxx.service的文件，文件内容如下：
[Unit]
    Description=mamba
    After=network.target
    After=mysql.service
    Requires=mysql.service
    [Service]
    User=root
    Group=root
    ExecStart=/www/server/php/74/bin/php /www/wwwroot/mamba/yii queue/listen --verbose
[Install]
WantedBy=multi-user.target
 *命令行启动：systemctl start xxxx
 * 查看状态：systemctl status xxxx
 * 停止：systemctl stop xxxx
 * 开机自启动：systemctl enable xxxx
 * Class QueueApi
 * @package common\helpers
 */
class QueueApi
{
    public function __construct()
    {
        try {

        }catch (\Exception $e){
            throw new Exception($e->getMessage());
        }
    }

    /**
     * 执行时间
     * @param $time
     * @param callable $callable
     */
    public function delay($time,$callable)
    {
        if ($time>0){
            Yii::$app->queue->delay($time)->push($callable);
        }else{
            Yii::$app->queue->push($callable);
        }
    }
}